<?php

$today = $_GET['today'];
$openid = $_GET['openid'];
$conn = mysqli_connect("localhost", "root", "", "cloudwarehouse");

if (!$conn)
    echo "数据库连接失败！";
else {
    $profit = array(5);
    for ($i = 0; $i < 5; $i++) {

        $beginmonth = date("Y-m-d", mktime(0, 0, 0, date('m') - $i, 1, date('Y')));
        $endmonth = date("Y-m-d", mktime(0, 0, 0, date('m') + 1 - $i * 1, 0, date('Y')));


        $sql_today = "SELECT sum(profit) FROM commodity_profit WHERE outboundDate BETWEEN '$beginmonth' AND '$endmonth' AND openid = '$openid'";
        $result_gettoday = mysqli_query($conn, $sql_today);
        $profit_todaypre = mysqli_fetch_array($result_gettoday);
        //今天利润
        if ($profit_todaypre[0] == NULL) {
            $profit[$i] = 0;
        } else {
            $profit[$i] = round($profit_todaypre[0], 2);
        }


        //本月开始时间
        //$beginThismonth = date("Y-m-d H:i:s",mktime(0,0,0,date('m'),1,date('Y')));
        //本月结束时间
        //$endThismonth = date("Y-m-d H:i:s",mktime(23,59,59,date('m'),date('t'),date('Y')));
        //上月开始时间
        //$beginLastmonth = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-1,1,date("Y")));
        //上月结束时间
        //$endLastmonth = date("Y-m-d H:i:s",mktime(23,59,59,date("m") ,0,date("Y")));
    }
    echo json_encode($profit);
}
